function ww=update_w(N,K,MG,hGA,hGG,mumu,eta,uu,vv)
ww = zeros(MG,N,K);
for nn=1:N
    for kk=1:K
        % 2. maximizing the Lagrangian
        % update ${\bf{W}}$ and obtain the Lagrange dual function
        denomi_W = zeros(MG,MG);
        for mm=1:N
            for ll=1:K
                denomi_W = denomi_W + hGG{nn,mm,ll}*(vv(mm,ll)*vv(mm,ll)')*hGG{nn,mm,ll}';
            end
        end
        denomi_W = denomi_W  + mumu*(hGA{nn}*hGA{nn}') + eta(nn)*eye(MG);
%         W{nn,kk} = inv(denominator_W) * hGG{nn,nn,kk}*V{nn,kk} * sqrt(weight{nn,kk}*(1+U{nn,kk}));
        ww(:,nn,kk) = denomi_W \ (hGG{nn,nn,kk}*vv(nn,kk) * sqrt((1+uu(nn,kk))));
    end
end
end